package com.qmhl.toolposition.wxapi

import android.content.Intent
import android.os.Bundle
import com.qmhl.toolposition.base.BaseActivity
import com.tencent.mm.opensdk.constants.ConstantsAPI
import com.tencent.mm.opensdk.modelbase.BaseReq
import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
import com.tencent.mm.opensdk.openapi.WXAPIFactory


class WXPayEntryActivity : BaseActivity(), IWXAPIEventHandler {

    lateinit var mIWXAPI: IWXAPI

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mIWXAPI = WXAPIFactory.createWXAPI(this, "wx6bb40171e11f15da");
        mIWXAPI.handleIntent(intent, this);
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        setIntent(intent);
        mIWXAPI.handleIntent(intent, this);
    }

    override fun onReq(p0: BaseReq?) {
        TODO("Not yet implemented")
    }

    //第三方应用发送到微信的请求处理后的响应结果，会回调到该方法

    override fun onResp(baseResp: BaseResp) {

        if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if (baseResp.errCode == 0) {
                //支付成功相关操作

            } else if (baseResp.errCode == -1) {
                //支付失败相关操作

            } else if (baseResp.errCode == -2) {
                //支付取消相关操作

            }
            finish();
        }
    }





}